package com.xintonghua.bussiness.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xintonghua.base.adapter.BaseAdapter;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.ClubCardBean;
import com.xintonghua.bussiness.bean.Contant;
import com.xintonghua.bussiness.util.GlideUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者：wanxianyi
 * 时间：2018/1/10.
 * 包名：com.xintonghua.hongyi.adapter
 */

public class ClubCardAdapter extends BaseAdapter<ClubCardBean.ListBean, ClubCardAdapter.HoldView> {


    Context context;

    public ClubCardAdapter(Activity mActivity, List<ClubCardBean.ListBean> list) {
        super(mActivity, list);
        context = (Context) mActivity;
    }

    @Override
    public HoldView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.adapter_club_card, parent, false);
        return new HoldView(view);
    }

    @Override
    public void onBindViewHolder(HoldView holder, final int position) {

        final ClubCardBean.ListBean bean = getList().get(position);
        holder.tvClubName.setText("" + bean.getName());
        holder.tvClubDegree.setText("余额:" + bean.getFrequency() + "次");
        GlideUtils.load(context, holder.ivClub, bean.getAvatar());

        holder.btnRecharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (rechargeInterface != null) {
                    rechargeInterface.rechargeClistener(bean, position);
                }
            }
        });
    }

    public void setOnRechargeClickClistener(RechargeInterface rechargeClickClistener) {
        this.rechargeInterface = rechargeClickClistener;
    }

    RechargeInterface rechargeInterface;

    public interface RechargeInterface {
        void rechargeClistener(ClubCardBean.ListBean bean, int position);
    }

    class HoldView extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_club)
        ImageView ivClub;
        @BindView(R.id.tv_club_name)
        TextView tvClubName;
        @BindView(R.id.btn_recharge)
        TextView btnRecharge;
        @BindView(R.id.tv_club_degree)
        TextView tvClubDegree;

        public HoldView(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
